$(function () {
    let data = {cuisineId: 0, page: 1, limit: 8};
    findNewsPage(data);
});

function findNewsPage(data) {
    $.ajax({
        url: '/front/findNewsData',
        data: data,
        dataType: 'json',
        type: 'get',
        success: function (data) {
            console.log(data);
            setCuisineData(data.cuisineModelList);
            setProductData(data.productModelList);

        }
    })

}

function setCuisineData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += ' <div onclick="findProductByCuisineId(' + data[i].id + ')">' + data[i].name + '</div>';
    }
    $("#cuisine").html();
}

/**
 * 根据菜系id查询产品，默认第一页
 * @param id
 */
function findProductByCuisineId(id) {
    sessionStorage.setItem("cuisineId",id);
    let data = {cuisineId: id, page: 1, limit: 8};
    findNewsPage(data);
}
layui.use(['laypage', 'layer'], function() {
    var laypage = layui.laypage
        , layer = layui.layer;

//总页数大于页码总数
    laypage.render({
        elem: 'demo1'
        , count: 1 //数据总数
        , jump: function (obj) {
            let data = {cuisineId: sessionStorage.getItem("cuisineId"), page: obj.curr, limit: 8};
            findNewsPage(data);
        }
    });
});